#!/usr/bin/env node

/*
 * asn1dump - simple ASN.1 dumper for ASN.1 DER binary file
 *
 * Copyright (c) 2015-2016 Kenji Urushima (kenji.urushima@gmail.com)
 *
 * This software is licensed under the terms of the MIT License.
 * https://kjur.github.io/jsrsasign/license
 *
 * The above copyright and license notice shall be 
 * included in all copies or substantial portions of the Software.
 * 
 * Please use '-h' option for this script usage.
 * ---------------------------------------------------------
 * DESCRIPTION
 *   This script shows ASN.1 dump of ASN.1 DER binary file.
 * 
 * USAGE
 *   % asn1dump req.der
 *   SEQUENCE
 *     SEQUENCE
 *       SEQUENCE
 *         ObjectIdentifier sha1 (1 3 14 3 2 26)
 *         NULL
 *       OCTETSTRING 7ae13ee8a0c42a2cb428cbe7a605461940e2a1e9
 *       OCTETSTRING 90af6a3a945a0bd890ea125673df43b43a28dae7
 *       INTEGER 00d09282634303a97fadf55568a48ca87e
 */

var program = require('commander');
var rs = require('jsrsasign');
var rsu = require('jsrsasign-util');

program
  .version('0.0.2')
  .usage('[options] <input file>')
  .description('show dump of ASN.1 DER file')
  .parse(process.argv);

if (program.args.length !== 1)
  throw "wrong number of arguments";

var file = program.args[0];

var bin = rsu.readFile(file);
var hex = rs.rstrtohex(bin);
console.log(rs.ASN1HEX.dump(hex));
